package la.iok.hzsvn.lewin.movie.operation.timer;

import la.iok.hzsvn.lewin.movie.operation.cfg.PlayRecordAutoEndProperties;
import la.iok.hzsvn.lewin.movie.operation.service.PlayRecordService;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

public class PlayRecordAutoEndScheduleService {
    private static final Logger logger = LoggerFactory.getLogger(PlayRecordAutoEndScheduleService.class);
    private final PlayRecordService playRecordService;
    private final PlayRecordAutoEndProperties playRecordAutoEndProperties;

    public PlayRecordAutoEndScheduleService(PlayRecordService playRecordService,
                                            PlayRecordAutoEndProperties playRecordAutoEndProperties) {
        this.playRecordService = playRecordService;
        this.playRecordAutoEndProperties = playRecordAutoEndProperties;
    }

    @Scheduled(cron = "0 */20 * * * *")
    public void doRefresh(){
        if(BooleanUtils.isTrue(playRecordAutoEndProperties.getEnabled())){
            int c = playRecordService.endBySystem();
            logger.info("结束{}个开本记录",c);
        }else{
            logger.info("自动结束未开启");
        }

    }
}
